package com.lincoln.cloud.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 配置读取工具
 *
 * @author lincoln
 */
public class ConfigUtil {
    /**
     * 读取配置
     *
     * @param path
     * @return
     */
    public static Properties loadProperties(String path) {
        try {
            Properties properties = new Properties();
            properties.load(new InputStreamReader(ConfigUtil.class.getClassLoader().getResourceAsStream(path), "GBK"));
            return properties;
        } catch (IOException e) {
            return null;
        }
    }

    /**
     * 附加配置
     *
     * @param path
     * @param properties
     * @return
     */
    public static Properties loadProperties(String path, Properties properties) {
        try {
            InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream(path);
            if(in == null){
                return properties;
            }
            properties.load(new InputStreamReader(in, "GBK"));
        } catch (IOException e) {

        }
        return properties;
    }
}
